<html>
  <head>
    <meta name="GENERATOR" content="BLOCKNOTE.NET"/>
    <meta name="source"/>
    <meta name="source"/>
    <basefont face="Verdana" size="2"/>
    <meta name="generator" content="h-smile:richtext"/>
  </head>
<body>
  <h1>Global namespace</h1>
  <p>Following functions and variables that &quot;live&quot; in global namespace so they accessible in script without any namespace designator, e.g.</p>
  <pre>var r = <em>eval</em>( <font color="#990099">&quot; 348.0 / 23.7 &quot;</font> );<br/><em>stdout</em>.printf( <font color="#990099">&quot;%f&quot;</font> , r );
</pre>
  <div align="left">
    <table border="0" cellpadding="4" cellspacing="0" width="100%">
      <tr>
        <td colspan="2" valign="middle">
          <h2>Global variables</h2></td>
        <td width="140"></td></tr>
      <tr>
        <td width="117" bgcolor="#ffffff" align="right"><strong><em>stdin</em></strong></td>
        <td bgcolor="#fffff0" valign="middle"><em>stream</em>, standard input stream. Read-only.</td>
        <td rowspan="3" width="140" bgcolor="#ffffff" valign="middle">
          <table align="left" border="0" cellpadding="0" cellspacing="4">
            <tr>
              <td><font size="6" color="#cc0000">!</font></td></tr></table>
          <div>These streams are created and managed by host application of the script engine</div></td></tr>
            <tr>
              <td width="117" bgcolor="#ffffff" align="right"><strong><em>stdout</em></strong></td>
              <td bgcolor="#fffff0" valign="middle"><em>stream</em>, standard output stream. Write-only.</td></tr>
            <tr>
              <td width="117" bgcolor="#ffffff" align="right"><strong><em>stderr</em></strong></td>
              <td bgcolor="#fffff0" valign="middle"><em>stream</em>, standard error stream. Engine reports here about all uncought exceptions.</td></tr>
            <tr>
              <td colspan="2" valign="top">
          <h2>Global functions</h2></td>
              <td width="140"></td></tr>
            <tr>
              <td bgcolor="#ffffff" valign="top" align="right"><strong><em>eval</em></strong></td>
              <td bgcolor="#fffff0" valign="middle">
          <div><strong>( </strong><em>input</em><strong> : </strong>string|stream <strong>&nbsp;</strong>[, <em>env</em> :object ]<strong> ) </strong>: <em>value</em></div>
          <p>Evaluates (interprets) <em>input</em> and returns its value. If <em>input </em>is a string then function tries to interpret it as if it &nbsp;contains script source code. If <em>input </em>is a <em>stream object</em> then it compiles and executes source code from it.</p>
          <p>Example: after execution of the following:</p>
          <pre>var obj = eval( <font color="#990099">&quot; ({ one:1, two:2 }) &quot;</font> );
</pre>
          <p>variable <em>obj</em> will contain object having two fields: <em>one</em> and <em>two.</em></p>
          <p><em>env</em> is an environment object - if provided then script execution takes place in the namespace of that object.</p>
          <pre>var env = { one:1, two:2 };<br/>var res = eval( <font color="#990099">&quot;one + two&quot;, </font>env);
</pre>
          <div>After execution of two lines above variable <em>res</em> will contain integer 3.</div></td>
              <td rowspan="8" width="140" bgcolor="#ffffff" valign="top">
          <table align="left" border="0" cellpadding="0" cellspacing="4">
            <tr>
              <td><font size="6" color="#cc0000">!</font></td></tr></table>
          <div>These functions available only if host application configured the engine to use them.</div></td></tr>
            <tr>
              <td bgcolor="#ffffff" valign="top" align="right"><strong><em>parseData</em></strong></td>
              <td bgcolor="#fffff0" valign="middle">
          <div><strong>( </strong><em>input</em><strong> : </strong>string|stream<strong> ) </strong>: <em>value</em></div>
          <p>a.k.a. JSON++ data parser.</p>
          <p>Evaluates (interprets) data literal at the <em>input</em> and returns its value. Input shall contain valid data literal expression otherwise parsing exception will be thrown.</p>
          <p>Example 1: after execution of the following:</p>
          <pre>var obj = parseValuel( <font color="#990099">&quot; { one:1, two:2 } &quot;</font> );
</pre>
          <p>variable <em>obj</em> will contain object having two fields: <em>one</em> and <em>two.</em></p>
          <div>Example 2: after execution of the following:</div>
          <pre>var v = parseValuel( <font color="#990099">&quot;3.1415926&quot;</font> );
</pre>
          <p>variable <em>v</em> will contain float number 3.1415926 - parsed value of the string<em>.</em></p>
          <p>Main difference from the <em>eval</em> function is that <em>parseValue</em> will not parse and execute any function declarations or functions so it is safe to use this function when data is coming from unknown sources e.g. in AJAX like of interactions.</p></td></tr>
            <tr>
              <td bgcolor="#ffffff" valign="top" align="right"><strong><em>emit</em></strong></td>
              <td bgcolor="#fffff0" valign="middle">
          <div><strong>( </strong><em>input</em> :string|stream,<strong> </strong><em>output </em>:stream<strong> </strong>[, <em>env</em> :object ] <strong>)</strong> :value</div>
          <p>Evaluates the <em>input</em> stream in serverScript mode (see below) and emits result to the <em>output</em> stream. Function assumes that executable script at the <em>input</em> is contained in &lt;% %&gt; brackets. Function returns result of first standalone <em>return</em> statement in the input stream.</p>
          <p><em>env</em> is an environment object, it allows to pass parameters to the input script from the caller.</p></td></tr>
            <tr>
              <td bgcolor="#ffffff" valign="top" align="right"><strong><em>load</em></strong></td>
              <td bgcolor="#fffff0" valign="middle">
          <div><strong>( </strong><em>source</em> [, <em>asServerScript</em>]<strong> )</strong> :true|false</div>
          <p>Loads (compiles and executes) <em>source</em>. Source here either string - <strong>file name</strong> or <strong>stream object</strong>. If <em>asServerScript</em> provided and equals to <em>true </em>then source is interpreted as a text with embedded script like PHP or ASP web page:</p>
          <p>&lt;html&gt; ... <font color="#990099">&lt;%</font> =some_script_function(); <font color="#990099">%&gt;</font>... &lt;/html&gt;</p>
          <p>These two fragments:</p>
          <pre><strong>load</strong>( <font color="#990099">&quot;c:/myscripts/test.js&quot;</font> );
</pre>
          <p>and</p>
          <pre>var s = Stream.openFile(<font color="#990099">&quot;c:/myscripts/test.js&quot;</font>,<font color="#990099">&quot;r&quot;</font>); <strong>load</strong>( s );
</pre>
          <p>are equivalent.</p>
          <p>Script execution takes place in the namespace of the caller of the function.</p></td></tr>
            <tr>
              <td bgcolor="#ffffff" valign="top" align="right"><strong><em>loadbc</em></strong></td>
              <td bgcolor="#fffff0" valign="middle">
          <div><strong>( </strong><em>source</em> <strong>)</strong> : <em>true</em> | <em>false</em></div>
          <p>Loads compiled bytecodes defined by <em>source</em>. Source here either string - <strong>file name</strong> or <strong>stream object</strong>.</p></td></tr>
            <tr>
              <td bgcolor="#ffffff" valign="top" align="right"><strong><em>compile</em></strong></td>
              <td bgcolor="#fffff0" valign="middle">
          <div><strong>( </strong><em>input</em> : filename | Stream, <em>output</em>: filename | Stream<strong> [, </strong><em>asServerScript</em><strong> </strong>: true | false<strong> ] &nbsp;) </strong>: true | false</div>
          <p>Calls built-in compiler to compile <em>input. </em>Writes output bytecodes into<em> out </em>stream or file. Bytecodes can be loaded (executed) later by <em>loadbc</em> function.</p></td></tr>
            <tr>
              <td bgcolor="#ffffff" valign="top" align="right"><strong><em>store</em></strong></td>
              <td bgcolor="#fffff0" valign="middle">
          <div><strong>( </strong><em>filename</em> | <em>stream</em>, <em>value</em><strong> ) </strong>:<strong> </strong><em>true</em> | <em>false</em></div>
          <p>Stores the <em>value</em> into file <em>filename </em>or <em>stream </em>in binary form<em>. </em>Returns <em>true</em> if data was stored successfully.</p></td></tr>
            <tr>
              <td bgcolor="#ffffff" valign="top" align="right"><strong><em>fetch</em></strong></td>
              <td bgcolor="#fffff0" valign="middle">
          <div><strong>( </strong><em>filename</em> | <em>stream</em><strong> ) </strong>:<strong> </strong>value | null</div>
          <p>Restores value previously written into the file (<em>filename</em>) or <em>stream</em> by function <em>store.</em> Returns value or <em>null</em> if operation failed.</p></td></tr>
            <tr>
              <td bgcolor="#ffffff" valign="top" align="right"><strong><em>hash</em></strong></td>
              <td colspan="2" bgcolor="#fffff0" valign="middle">
          <p><strong>( </strong><em>value</em><strong> ) </strong>: integer</p>
          <p>Returns hash value of its argument.</p></td></tr>
            <tr>
              <td bgcolor="#ffffff" valign="top" align="right"><strong><em>membersOf</em></strong></td>
              <td colspan="2" bgcolor="#fffff0" valign="middle">
          <p>( obj: object | function ) : map (object)</p></td></tr>
            <tr>
              <td bgcolor="#ffffff" valign="top" align="right"></td>
              <td colspan="2" bgcolor="#fffff0" valign="middle">
          <p>Returns map (simple object) that has the same set of properties as the obj. Main purpose of <em>membersOf</em> is to be used in <code>for( var (k,v) in membersOf(obj))</code> alike enumerations to scan properties of entities that have different semantic of enumeration than in instances of Object. Example:</p>
          <pre>function Foo() { ... }
Foo.bar = 1; // adding property 'bar' to the
             // Foo function (that is an object too)
for(var (k,v) in Foo ) 
  ... // here you should see k equal to #bar <br/>      // on some iteration
</pre></td></tr>
            <tr>
              <td bgcolor="#ffffff" valign="top" align="right"><strong><em>rand</em></strong></td>
              <td colspan="2" bgcolor="#fffff0" valign="middle">
          <p><strong>( </strong><em>maxNumber</em><strong> )</strong> : integer</p>
          <p>Returns a random number between 0 and maxNumber-1.</p></td></tr>
            <tr>
              <td bgcolor="#ffffff" valign="top" align="right"><strong><em>gc</em></strong></td>
              <td colspan="2" bgcolor="#fffff0" valign="middle">
          <div><strong>( )</strong> : <em>undefined</em></div>
          <p>Invokes garbage collector.</p></td></tr>
            <tr>
              <td bgcolor="#ffffff" valign="top" align="right"><strong><em>crackUrl</em></strong></td>
              <td colspan="2" bgcolor="#fffff0" valign="middle">
          <div><strong>( </strong><em>url</em>:string<strong> )</strong> : object</div>
          <p>Parses the url string. Returns an object having following fields:</p>
          <ul>
            <li><em>port</em> - integer, tcp/ip port number;</li>
            <li><em>protocol</em> - string, protocol like &quot;http&quot;, &quot;file&quot;, etc.;</li>
            <li><em>hostname</em> - string, host name;</li>
            <li><em>anchor</em> - string, anchor;</li>
            <li><em>username</em> - string;</li>
            <li><em>password</em> - string;</li>
            <li><em>params</em> - string, parameters of http GET request</li>
            <li><em>dir</em> - string, directory</li>
            <li><em>name</em> - string, filename without extension</li>
            <li><em>ext</em> - &nbsp;string, extension</li>
            <li><em>name_ext</em> - string, filename with extension.</li></ul></td></tr>
            <tr>
              <td bgcolor="#ffffff" valign="top" align="right"><em><strong>symbol</strong></em></td>
              <td colspan="2" bgcolor="#fffff0" valign="middle">
          <div>( <em>string</em> ) : symbol</div>
          <p>Function returns symbol of the string. Internally symbol is 32bit value so symbol space is limited - it makes no sense to &quot;symbolize&quot; arbitrary strings.</p></td></tr>
            <tr>
              <td bgcolor="#ffffff" valign="top" align="right"><strong><em>color</em></strong></td>
              <td bgcolor="#fffff0" valign="middle">(<strong>r</strong>: int, <strong>g</strong>: int, <strong>b</strong>: int [, <strong>opacity</strong>: int | float]) : color
          <p>The <em>color</em> function constructs color value from red, green, blue and opacity components.</p></td>
              <td bgcolor="#fffff0" valign="middle"></td></tr>
            <tr>
              <td bgcolor="#ffffff" valign="top" align="right"><em><strong>em</strong></em></td>
              <td bgcolor="#fffff0" valign="middle">
          <div>(<strong> v</strong>: int | float ) : length, these functions constructs length values of correspondent type.</div></td>
              <td bgcolor="#fffff0" valign="middle">
          <div></div></td></tr>
            <tr>
              <td bgcolor="#ffffff" valign="top" align="right"><strong><em>pr</em></strong></td>
              <td bgcolor="#fffff0" valign="middle">
          <div>(<strong> v</strong>: int | float ) : length</div></td>
              <td bgcolor="#fffff0" valign="middle">
          <div></div></td></tr>
            <tr>
              <td bgcolor="#ffffff" valign="top" align="right"><strong><em>px</em></strong></td>
              <td bgcolor="#fffff0" valign="middle">
          <div>(<strong> v</strong>: int | float ) : length</div></td>
              <td bgcolor="#fffff0" valign="middle">
          <div></div></td></tr>
            <tr>
              <td bgcolor="#ffffff" valign="top" align="right"><strong><em>cm</em></strong></td>
              <td bgcolor="#fffff0" valign="middle">
          <div>(<strong> v</strong>: int | float ) : length</div></td>
              <td bgcolor="#fffff0" valign="middle">
          <div></div></td></tr>
            <tr>
              <td bgcolor="#ffffff" valign="top" align="right"><strong><em>pt</em></strong></td>
              <td bgcolor="#fffff0" valign="middle">
          <div>(<strong> v</strong>: int | float ) : length</div></td>
              <td bgcolor="#fffff0" valign="middle">
          <div></div></td></tr>
            <tr>
              <td bgcolor="#ffffff" valign="top" align="right"><strong><em>dip</em></strong></td>
              <td bgcolor="#fffff0" valign="middle">
          <div>(<strong> v</strong>: int | float ) : length</div></td>
              <td bgcolor="#fffff0" valign="middle">
          <div></div></td></tr>
            <tr>
              <td bgcolor="#ffffff" valign="top" align="right"><em><strong>flex</strong></em></td>
              <td bgcolor="#fffff0" valign="middle">
          <div>(<strong> v</strong>: int | float ) : length, flex unit value</div></td>
              <td bgcolor="#fffff0" valign="middle">
          <div></div></td></tr></table></div>
  <div></div>
</body>
</html>